package com.yikaiye.android.yikaiye.ui.fragment.viewmodel;

import androidx.lifecycle.MutableLiveData;

import com.google.gson.Gson;
import com.yikaiye.android.yikaiye.base.BaseViewModel;
import com.yikaiye.android.yikaiye.config.Constant;
import com.yikaiye.android.yikaiye.di.retrofit.BaseModel;
import com.yikaiye.android.yikaiye.di.retrofit.BaseNetCallback;
import com.yikaiye.android.yikaiye.model.ServiceRecordsModel;

import java.util.HashMap;
import java.util.Map;

public class ServiceListViewModel extends BaseViewModel {

    public MutableLiveData<ServiceRecordsModel> serviceRecordsModelMutableLiveData = new MutableLiveData<>();

    /**
     * 服务列表
     *
     * @param page   页码
     * @param status 服务状态：0.待办 1.在办 2.暂停 3.已办结 4.已终止
     */
    public void getServiceList(int page, String status) {
        Map<String, Object> map = new HashMap<>();
        map.put("pageNum", page);
        map.put("pageSize", Constant.PAGE_SIZE);
        map.put("status", status);
        addSubscribe(mRetrofitHelper.getServiceList(new Gson().toJson(map)).subscribeWith(new BaseNetCallback<ServiceRecordsModel>() {

            @Override
            public void onSuccess(BaseModel<ServiceRecordsModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode()) {
                    if (null != baseModel.getData()) {
                        serviceRecordsModelMutableLiveData.setValue(baseModel.getData());
                    }
                }
            }
        }));
    }
}
